<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>知识库管理</title>
    <link rel="stylesheet" href="/static/bootstrap.min.css">
</head>
<body>
    <div class="container mt-4">
        <h2>知识库管理</h2>
        <form action="{{ url_for('add_knowledge_base') }}" method="post" class="mb-4">
            <div class="mb-3">
                <label for="title" class="form-label">标题</label>
                <input type="text" class="form-control" id="title" name="title" required>
            </div>
            <div class="mb-3">
                <label for="remark" class="form-label">备注</label>
                <textarea class="form-control" id="remark" name="remark"></textarea>
            </div>
            <div class="mb-3">
                <label for="sort" class="form-label">排序</label>
                <input type="number" class="form-control" id="sort" name="sort" required>
            </div>
            <div class="mb-3 form-check">
                <input type="checkbox" class="form-check-input" id="enabled" name="enabled" checked>
                <label class="form-check-label" for="enabled">启用</label>
            </div>
            <button type="submit" class="btn btn-primary">添加知识库</button>
        </form>
        <table class="table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                    <th>备注</th>
                    <th>排序</th>
                    <th>启用</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for kb in knowledge_bases %}
                <tr>
                    <td>{{ kb[0] }}</td>
                    <td>{{ kb[1] }}</td>
                    <td>{{ kb[2] }}</td>
                    <td>{{ kb[3] }}</td>
                    <td>{{ '是' if kb[4] else '否' }}</td>
                    <td>
                        <a href="{{ url_for('edit_knowledge_base', id=kb[0]) }}" class="btn btn-sm btn-warning">编辑</a>
                        <a href="{{ url_for('delete_knowledge_base', id=kb[0]) }}" class="btn btn-sm btn-danger" onclick="return confirm('确定要删除吗？')">删除</a>
                    <a href="{{ url_for('upload_page', id=kb[0]) }}" class="btn btn-sm btn-info">管理知识</a>
                    <a href="{{ url_for('status', id=kb[0]) }}" class="btn btn-sm btn-success">查看文档</a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</body>
</html>